﻿using AG.Data;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace AGMapEditor.Windows
{
    public partial class AGCreateSwitchPointWindow : Form
    {
        private AGMap _map;

        public AGMapSwitchPoint CreatedSwitchPoint { get; private set; }

        public AGCreateSwitchPointWindow(AGMap map)
        {
            InitializeComponent();

            _map = map;
            _ctlEditSrcMap.Text = _map.Name;
        }

        private void _ctlBtnCreate_Click(object sender, EventArgs e)
        {
            try
            {
                int id = Convert.ToInt32(_ctlEditId.Text);
                int srcRangeRow = Convert.ToInt32(_ctlEditSrcRangeRow.Text);
                int srcRangeCol = Convert.ToInt32(_ctlEditSrcRangeCol.Text);
                int srcRangeRowCount = Convert.ToInt32(_ctlEditSrcRangeRowCount.Text);
                int srcRangeColCount = Convert.ToInt32(_ctlEditSrcRangeColCount.Text);

                int targetMapId = (_ctlBtnTargetMap.Tag as AGMap).Id;
                int targetPosRow = Convert.ToInt32(_ctlEditTargetRow.Text);
                int targetPosCol = Convert.ToInt32(_ctlEditTargetCol.Text);

                CreatedSwitchPoint = new AGMapSwitchPoint();
                CreatedSwitchPoint.Id = (ushort)id;
                CreatedSwitchPoint.Range = new Rectangle(srcRangeRow, srcRangeCol, srcRangeRowCount, srcRangeColCount);
                CreatedSwitchPoint.TargetMapId = (ushort)targetMapId;
                CreatedSwitchPoint.TargetMapCaption = _ctlBtnTargetMap.Text;
                CreatedSwitchPoint.TargetPosRow = (ushort)targetPosRow;
                CreatedSwitchPoint.TargetPosCol = (ushort)targetPosCol;

                DialogResult = System.Windows.Forms.DialogResult.OK;
            }
            catch
            {
            }
        }

        private void _ctlBtnTargetMap_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            AGSelectMapWindow window = new AGSelectMapWindow(_map);
            if (window.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                _ctlBtnTargetMap.Text = window.SelectedMap.Name;
                _ctlBtnTargetMap.Tag = window.SelectedMap;
            }
        }
    }
}
